package com.lwj.widget.viewpagerindicator_demo.slice;

import com.lwj.widget.viewpagerindicator.ResourceTable;
import com.lwj.widget.viewpagerindicator.ViewPagerIndicator;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.PageSlider;
import ohos.agp.components.PageSliderProvider;
import ohos.agp.components.Text;
import ohos.app.Context;

import java.util.ArrayList;

import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT;

/**
 * BlankFraction
 *
 * @author name
 * @since 2021-03-20
 */
public class NotCarouselAbilitySlice extends AbilitySlice {
    private static final int TEXT_WIDTH = 100;
    private static final int TEXT_HEIGHT = 100;
    private static final int TEXT_SIZE = 40;
    private PageSlider mPageSlider;
    private ViewPagerIndicator mIndicatorDefault;
    private ViewPagerIndicator mIndicatorCircle;
    private ViewPagerIndicator mIndicatorLine;
    private ViewPagerIndicator mIndicatorCircleLine;
    private ViewPagerIndicator mIndicatorBazier;
    private ViewPagerIndicator mIndicatorSpring;
    private ViewPagerIndicator mIndicatorProgress;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_not_carouse);
        mPageSlider = (PageSlider) findComponentById(ResourceTable.Id_not_page_slider);
        ArrayList<String> strings = new ArrayList<>();
        strings.add("NO.1");
        strings.add("NO.2");
        strings.add("NO.3");
        strings.add("NO.4");

        MinePageSlider minePageSlider = new MinePageSlider(strings, this);
        mPageSlider.setProvider(minePageSlider);
        mIndicatorDefault = (ViewPagerIndicator) findComponentById(ResourceTable.Id_not_default_indicator);
        mIndicatorCircle = (ViewPagerIndicator) findComponentById(ResourceTable.Id_not_circle_indicator);
        mIndicatorLine = (ViewPagerIndicator) findComponentById(ResourceTable.Id_not_line_indicator);
        mIndicatorCircleLine = (ViewPagerIndicator) findComponentById(ResourceTable.Id_not_circle_line_indicator);
        mIndicatorBazier = (ViewPagerIndicator) findComponentById(ResourceTable.Id_not_bezier_indicator);
        mIndicatorSpring = (ViewPagerIndicator) findComponentById(ResourceTable.Id_not_spring_indicator);
        mIndicatorProgress = (ViewPagerIndicator) findComponentById(ResourceTable.Id_not_process_indicator);
        mIndicatorDefault.setViewPager(mPageSlider);
        mIndicatorCircle.setViewPager(mPageSlider);
        mIndicatorLine.setViewPager(mPageSlider);
        mIndicatorCircleLine.setViewPager(mPageSlider);
        mIndicatorBazier.setViewPager(mPageSlider);
        mIndicatorSpring.setViewPager(mPageSlider);
        mIndicatorProgress.setViewPager(mPageSlider);
    }

    /**
     * MinePageSlider
     *
     * @since 2021-05-24
     */
    public static class MinePageSlider extends PageSliderProvider {
        private Context mContext;
        private ArrayList<String> mStrings;

        /**
         * MinePageSlider
         *
         * @param strings
         * @param mcContext
         * @since 2021-05-24
         */
        public MinePageSlider(ArrayList<String> strings,Context mcContext) {
            super();
            mStrings = strings;
            this.mContext = mcContext;
        }

        @Override
        public int getCount() {
            return mStrings.size();
        }

        @Override
        public Object createPageInContainer(ComponentContainer componentContainer, int i) {
            Text notCarouseText = new Text(mContext);
            notCarouseText.setWidth(TEXT_WIDTH);
            notCarouseText.setHeight(TEXT_HEIGHT);
            notCarouseText.setText(mStrings.get(i));
            notCarouseText.setTextSize(TEXT_SIZE);
            DirectionalLayout directionalLayout = new DirectionalLayout(mContext);
            directionalLayout.setOrientation(Component.VERTICAL);
            directionalLayout.setLayoutConfig(new ComponentContainer.LayoutConfig(MATCH_PARENT, MATCH_PARENT));
            directionalLayout.addComponent(notCarouseText);
            componentContainer.addComponent(directionalLayout);
            return directionalLayout;
        }

        @Override
        public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
            componentContainer.removeComponent((Component) o);
        }

        @Override
        public boolean isPageMatchToObject(Component component, Object o) {
            return false;
        }
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
